package com.lw.leetcode.str;

import java.util.Stack;

/**
 *
 */
public class BackspaceCompare {

    public static void main(String[] args) {

        BackspaceCompare test = new BackspaceCompare();
        boolean b = test.backspaceCompare("ab#c", "ad#c");
        System.out.println(b);
    }
    public boolean backspaceCompare(String s, String t) {
        int a = s.length();
        int b = t.length();
        int m = a - 1;
        int n = b - 1;
        char p;
        char q;
        while (true) {
            while (true) {
                p = s.charAt(m);
                if (p == '#') {
                    m = m - 2;
                    if (m < 0) {
                        p = ' ';
                        break;
                    }
                } else {
                    m--;
                    break;
                }
            }
            while (true) {
                q = t.charAt(n);
                if (q == '#') {
                    n = n - 2;
                    if (n < 0) {
                        q = ' ';
                        break;
                    }
                } else {
                    n--;
                    break;
                }
            }
            if (n == -1 || m == -1 || p == ' ' ||  q == ' ') {
                return q == p;
            }
            if (q != p) {
                return false;
            }
        }
    }
}
